/*
vuex状态管理入口
 */

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const state = {
  books: []
}
const mutations = {
  addBook(state,{books}){
    state.books = books
  }
}
const actions = {
  getBooks({commit}, keyword) {
    axios.get(`http://localhost:8080/parse/${keyword}`).then(response => {
      console.log(response.data)
      console.log(response)
      const books =response.data
      commit("addBook",{books})
    }).catch(error => {
      alert(error)
    })
  }
}
const getters = {
  books(state){
    return state.books
  }
}
export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters

})
